<?php
/**
 * 活动商品模板
 * 
 */
defined('InShopNC') or exit('Access Invalid!');

class goods_templatesModel extends Model{
    public function __construct(){
        parent::__construct('goods_templates');
    }
    
   
    
    /**
     * 活动商品列表
     */
    public function goods_templates_list($condition){
        if ($condition['gt_class_id']==0){
            return Model()->table('goods_templates')->order('gt_class_id asc')->limit(false)->select();
            
        }else{
            return Model()->table('goods_templates')->where($condition)->order('gs_tp_id asc')->limit(false)->select();
            
        }
        
    }
    
    /**
     * 活动商品列表
     */
    public function goods_tp_list($condition){
        
        return Model()->table('goods_templates')->where($condition)->order('gs_tp_id asc')->limit(false)->select();
    
    }
    
    /**
     * 删除上商品活动内容
     * 
     */
    public function delete_content($condition){
        return $this->where($condition)->delete();
    } 
    
    /**
     * 单个活动商品
     */
    public function goods_templates_info($condition){
        return Model()->table('goods_templates')->where($condition)->find();
    }
   
    
    /**
     * 新增活动商品
     */
    public function addGoods_templates($data){
        if($data['gs_tp_id']){
            $condition['gs_tp_id']=$data['gs_tp_id'];
            unset($data['gs_tp_id']);
            $result = $this->table('goods_templates')->where($condition)->update($data);
            return $result;
        }else{
            return $this->table('goods_templates')->insert($data);
        }
        
    }
    
    /**
     * 查询当次活动的商品个数
     */
    public function get_goods_count($condition){
        $gt_list=$this->goods_templates_list($condition);
        $count=count($gt_list);
        return $count;
    }
    
    
    
}